<?php
/**
 * Created by zengwei.
 * Date: 2019/10/9
 * Time: 15:14
 * Function:
 */

namespace App\Http\Controllers\Web;


use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use QL\Ext\Chrome;
use QL\QueryList;
use Tymon\JWTAuth\Facades\JWTAuth;

class IndexController extends Controller
{
    public function index(){
        return view('web.app');
    }

    public function loginView(){
        return view('web.login');
    }

    public function login(){
        $user = (new User())->where('username',request()->input('username',''))->first();
        if(!$user){
            return response()->json(failDataFormat('账号不存在'));
        }
        if(!Hash::check(request()->input('password',''),$user->password)){
            return response()->json(failDataFormat('密码不存在'));
        }
        Auth::guard('web')->login($user);
        $token = $user->createToken('web');
        //jwt
        //$token = JWTAuth::fromUser($user);

        return response()->json(successDataFormat('success',$token));
    }

    public function test(){
        $url = 'http://127.0.0.1:8000/ddoc#/database';
        $ql = QueryList::getInstance();
        $ql->use(Chrome::class);
        $html = $ql->chrome($url)->html();
        echo $html;
    }

}
